package com.venusj.dubbo;

import com.venusj.dubbo.consumer.ConsumerComponent;
import com.venusj.dubbo.service.api.HelloService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.util.concurrent.Future;

/**
 * @author venusj
 * @date 2020/12/6
 */
public class XMLConsumerMain {
    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext applicationContext
                = new ClassPathXmlApplicationContext("consumer.xml");

        HelloService helloService = applicationContext.getBean(HelloService.class);

        while (true) {
            System.in.read();
            try {
                String hello = helloService.sayHelloByWait("world", 1000);
                Future<Object> future = RpcContext.getContext().getFuture();
                System.out.println("result :" + hello);
                System.out.println("future result :" + future.get());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "com.venusj.dubbo")
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(value = {"com.venusj.dubbo.consumer"})
    static class ConsumerConfiguration {
    }
}
